Installing Stata with Windows on Amazon EC2

Date: April 2015

The following is a simple guide to installing Stata on Windows using Amazon EC2, which I created to help out fellow UC Berkeley researchers who have stopped by D-Lab. I was not able to find anything similar on the web so I hope this can facilitate people trying out EC2 and providing a low-effort way to gain capacity beyond a single laptop. Of course using Linux and R or Python is also a good approach but plenty of guides already exist to do that (I use the Berkeley Common Environment AMI personally). Any questions or comments would be greatly appreciated!

  1. Create an Amazon AWS account.
    • Academics can sign up for extra educational credits through the AWS Educate program.
    • You may want to consult IT services at your institution to determine if discounts or other negotiations are in place with Amazon.
    • AWS in Education Grants are worth considering as well if you are at an educational institution.
    • Note: it can take two hours or so for Amazon to activate a new AWS account, so you may need to take a break before you are able to create a new compute instance.
  2. Login at - click the “Sign in to the Console” button.
  3. Click EC2 in the upper left corner. It should be the first service in the list.
  4. Click “Launch Instance”.
  5. Scroll down the Quick Start list to choose your AMI. An easy choice is “Microsoft Windows Server 2012 R2 Base” with 64-bit architecture. The logo will say “free tier eligible.” Click the blue “Select” button.
  6. Choose the instance that you want based on how powerful of a server you need. You can review the pricing here (be sure to click the “Windows” pricing tab, and select the region you intend to use).
    • One of the “memory optimized” r3 options or “computer optimized” c3/c4 options is often good for data analysis. For large datasets you can choose “r3.4xlarge” which currently boasts 16 virtual CPUs and 122GB of RAM and costs about $2 per hour.
    • Otherwise choose a server that has sufficient ram to load your desired datasets, plus some breathing room (at least 2gb but preferably 4gb+), and a good number of virtual CPUs if you have Stata MP.
      • Hard drive side is usually not that important because you can always create a separate EBS volume (think external hard drive) and attach that to your instance for extra storage.
  7. Click the blue button “Review and Launch.”
  8. Click “Edit security groups” - currently the third link on the right side of the page.
  9. Select “Create a new security group” - this should be selected by default.
  10. The default rule should be “RDP”. Go to the “Source” box and change the selection from “Anywhere” to “My IP”.
    • That allows you to connect remotely from your current IP and nowhere else, which drastically improves security for the EC2 instance.
    • Alternatively you can select “Custom IP” and list all IPs that you would use to connect from, with a comma between each IP.
    • If you change IPs you won’t be able to connect to the instance, so you will want to be able to connect from one or two relatively stable IPs (like your home and work IPs).
    • Or you can risk it and leave the original “” to not restrict what IPs are allowed to connect to the instance.
  11. Change the security group name to “Stata and Windows” or similar, and customize the description if you like.
  12. Click “Review and Launch” then “Launch”.
  13. Create a security key pair if you have not already done so.
    • Click “create a new key pair”
    • Make the name be “Stata and Windows key” or similar.
    • Click “download key pair” and save it to a folder that you will remember, like “Documents / Amazon EC2 / Key pairs”.
  14. Click “Launch Instances”
  15. Click “View instances”
  16. Find the new instance that you just launched, which will initially say “pending” in the “Instance State” column.
  17. Move your mouse to the blank space under the name column, click the pencil icon to edit the name, and name the instance something like “Stata and Windows”.
  18. In a minute or two the Instance State column will change to green “running”.
  19. Once it is running, right click the “running” text and select “Get windows password”
    • Initially it will say “Password not available yet”
    • Wait another minute and click the “Try again” orange link.
  20. Continue this until the instance has booted up and you can retrieve the password.
    • Next to “Key Pair Path” click the “choose file” button and navigate to the folder where you saved your key pair. Select that file.
    • Click “Decrypt Password”
    • Select the Public IP, username, and password text and paste them into a text file so that we can use them in a minute.
    • Select the password text and copy it to your clipboard so that you can paste it later.
    • Click the “Close” button to close that dialog box.
  21. Right click the “running” text again and select “Connect”
  22. Click “Download Remote Desktop File”
  23. On your computer, open the Microsoft Remote Desktop application.
    • If you're on OSX, you might also try the CoRD remote desktop application for connecting, which some people prefer to Microsoft Remote Desktop. In my experience it doesn't open the .rdp file from Amazon automatically so you have to add the connection manually (IP address, username).
  24. Click File -> Import, and select the RDP file that you just downloaded.
  25. You will see a new Desktop option in Microsoft Remote Desktop with the IP of the Amazon server.
    • Right click the IP and select “Edit”
    • Put a name into the “Connection Name” box, like “Windows on Amazon EC2”
    • IMPORTANT: whenever you start up your instance again in the future it will have a different IP address, assigned randomly by Amazon. You will need to edit the "PC name" field here and paste in the updated IP address (or DNS name - they are the same thing) so that you can connect. Alternatively you can re-download the remote desktop file from Amazon, which will have the updated IP address, and re-add it to Microsoft Remote Desktop, but that takes more configuration.
    • Click the “Redirection” tab then click the “+” icon at the bottom to add folders on your local computer that you want to be able to access on your Amazon instance.
    • Even though you will be able to “see” these folders in the Amazon Windows instance, if you want to use or copy those files on the instance they will be transferring across the internet from your local computer to Amazon. As a result any large files will be extremely slow to access until they have been fully copied from your local computer to the cloud instance.
    • Click the red “x” to close the dialog.
  26. Double-click the IP address of your remote instance to connect to it.
  27. Once you get to the login screen, paste your password into the paste box. You may need to type it out manually.
  28. You may want to change the password on the instance to something that you will remember.
    • Click the Windows icon on the left side of the bottom task menu.
    • Click Control Panel then under “User Accounts” click Change Account Type
    • Click the Administrator account, then “Change the password”
    • Enter the default password from Amazon, then change the new password to something you will remember.
  29. You may want to disable Internet Explorer Enhanced Security.
    • Click the “Server Manager” icon on the bottom taskbar (2nd icon from the left).
    • Click “Local Server” on the left side list.
    • On the right side column of items, click “On” next to “IE Enhanced Security Configuration”
    • Select “Off” for Administrators.
    • This will allow you to download executable files from, for example (like the Stata installation program).
  30. Install Stata
    • You will need to copy the installation executable file to the Amazon server. For Stata 13 it is named "SetupStata13.exe". You could do this by uploading the file to Dropbox or by copying it to a folder on your laptop and then sharing that folder with the Amazon instance.
    • After Stata is installed you will need to enter the Serial number, Code, and Authorization from your Stata license.
  31. Start analyzing!
  32. When you are done, you can go back to your Amazon console, right click the instance, and select “ Instance State -> Stop” to stop the instance.
    • At this point you will no longer be paying for compute time, but you will be paying a slight amount for the hard drive to stay available.
  33. You can then right click and select “Image -> Create Image” to create a backup of your EC2 cloud computer.
    • In the image name box, name it something like "Windows Stata April 28" (or whatever date it is for you).
    • Click "Create Image".
  34. Click to the AMIs section (left menu) and wait until the image has been created.
    • The image can then be used the next time you launch an instance. Instead of selecting the “Microsoft Windows Server 2012 R2 Base” you would click to “My AMIs” and choose this AMI out of the list.
      • This allows you to have all of your software and data ready to go within minutes.
    • You will then be charged a small amount per month based on the size of the image.
  35. Then go back to instance, right click, and select “Instance State -> Terminate” to remove the instance.


After helping a few people figure out errors in their setup, I am starting a trouble-shooting section below:

  1. Can’t connect to the server?
    • Check your wireless network. If you are connected to a “visitor” or “guest” network it may not allow Remote Desktop connections. Make sure that you are using the full authorized wireless network.

Stumbling blocks, questions, or other suggestions to improve the guide? Please post in the comments. I have only been able to try this out from my Mac laptop, so if there are any improvements to the instructions that could be made for Windows users I'd be glad to incorporate those. I'm also planning to add in some screenshots and/or a screencast when I have a chance.

Chris Kennedy
Instructor in psychiatry
comments powered by Disqus